﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WoChu.RfClient.Entity;
using WoChu.RfClient.Common;
using WoChu.CF.BaseFrame.Util;

namespace WoChu.RfClient.Duty
{
    public partial class FrmUpRack : Form
    {
        public FrmUpRack()
        {
            InitializeComponent();

        }

        private void FrmUpRack_Load(object sender, EventArgs e)
        { 
            string _WarehouseDate = DateTime.Now.ToString("yyyy-MM-dd");
            var re = Duty.DutyUIRule.NewInstance.GetPDAWarehouse(_WarehouseDate);

            if (re.ResultCode.Equals("1"))
            {
                //初始化数据
                this.UpRackSource.DataSource = re.Params;
                this.dbGridUpRack.DataSource = this.UpRackSource;

                txtCount.Text = re.Params.Count.ToString();
                
            }
            else
            {
                MessageBox.Show(re.Message);
                FrmUpRack_Closed(sender, e);
            }       
        }

        //上架
        private void btnUpRack_Click(object sender, EventArgs e)
        {
            string _WarehouseDate = DateTime.Now.ToString("yyyy-MM-dd");

            if (DutyUIRule.NewInstance.UpdatePDAWarehouseState(_WarehouseDate, LoginBean.Instance.USERCODE) > 0)
            {
                WoChu.CF.BaseFrame.Util.MessageBoxEx.Show("上架成功！");
            }
            else
            {
                WoChu.CF.BaseFrame.Util.MessageBoxEx.Show("失败！");
            }
        }

        private void FrmUpRack_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                if (MessageBoxEx.Question("确定退出吗？未提交的数据将丢失！") == DialogResult.Yes)
                {
                    //System.Reflection.Assembly ass = System.Reflection.Assembly.Load("WoChu.RfClient.Login");
                    //Type type = ass.GetType("WoChu.RfClient.Login.FrmMain");
                    //Object o = Activator.CreateInstance(type);
                    //System.Reflection.MethodInfo mi = type.GetMethod("Show");

                    //mi.Invoke(o, null);

                    this.Close();
                    this.Dispose();
                }
            }
        }

        private void FrmUpRack_Closed(object sender, EventArgs e)
        {
            //System.Reflection.Assembly ass = System.Reflection.Assembly.Load("WoChu.RfClient.Login");
            //Type type = ass.GetType("WoChu.RfClient.Login.FrmMain");
            //Object o = Activator.CreateInstance(type);
            //System.Reflection.MethodInfo mi = type.GetMethod("Show");

            //mi.Invoke(o, null);

            this.Close();
            this.Dispose();
        }
    }
}